﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MDF.DataHelper.BussinessObject.NewsBO;
using MDF.DataHelper.DataObject.NewsDO;
using System.Data;
using MDF.Utilites.Tools;

namespace MDF.DataHelper.BussinessLogic.NewsBL
{
    public class CommentBUS : BaseBussinessLogic
    {
        #region staticMember
        /// <summary>
        /// 
        /// </summary>
        private static CommentBUS _instance;
        /// <summary>
        /// 
        /// </summary>
        public static CommentBUS Current
        {
            get { return _instance == null ? _instance = new CommentBUS() : _instance; }
        }
        #endregion

        public bool Insert(int NewsID, int LangID, string Name, string Email, string Phone, string Address, string _Comment, string IP)
        {
            _Comment = _Comment.Trim().Replace("\r\n", "<br/>");

            CommentDAO objNewsDAO = new CommentDAO(this.m_objData);
            objNewsDAO.Insert( NewsID,  LangID,  Name,  Email,  Phone,  Address,  _Comment,  IP);

            return true;
        }

        public List<Comment> Select(int newsID, int iLang)
        {
            DataTable dt = new DataTable();
            CommentDAO objNewsDAO = new CommentDAO(this.m_objData);
            dt = objNewsDAO.Select(newsID, iLang);
            var lstTemp = dt.ToList<Comment>();
            return lstTemp;
        }

        public List<Comment> GetAll(int _iPage,int _iPageSize)
        {
            DataTable dt = new DataTable();
            CommentDAO objNewsDAO = new CommentDAO(this.m_objData);
            dt = objNewsDAO.GetAll(_iPage, _iPageSize);
            var lstTemp = dt.ToList<Comment>();
            return lstTemp;
        }

        public int CountNotRead()
        {
            CommentDAO objNewsDAO = new CommentDAO(this.m_objData);
            return (int) objNewsDAO.CountNotRead();
        }

        public bool Delete(string id)
        {
            CommentDAO objNewsDAO = new CommentDAO(this.m_objData);
            objNewsDAO.Delete(id);
            return true;
        }

        public List<Comment> GetNewComments(int iPage, int iPageSize)
        {
            DataTable dt = new DataTable();
            CommentDAO objNewsDAO = new CommentDAO(this.m_objData);
            dt = objNewsDAO.GetNewComments(iPage, iPageSize);
            var lstTemp = dt.ToList<Comment>();
            return lstTemp;
        }

        public void SetRead(int iCommentID)
        {
            CommentDAO objNewsDAO = new CommentDAO(this.m_objData);
            objNewsDAO.SetRead(iCommentID);
        }
    }
}
